package com.zbf.tspring.exceptionHandler;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/3/23  15:04
 * 描述:
 */

//@RestControllerAdvice
public class MyExceptionHandler {


    @ExceptionHandler(RuntimeException.class)
        public Object runTimeExceptionHandler(RuntimeException e){

        System.out.println("===========做出固定的处理=========="+e.getMessage());

         Map<String,Object> map=new HashMap<>();
         map.put("code",e.getMessage());

        return map;
    }

    @ExceptionHandler(ArrayIndexOutOfBoundsException.class)
    public Object runTimeExceptionHandler2(ArrayIndexOutOfBoundsException e){

        System.out.println("======ArrayIndexOutOfBoundsException=====做出固定的处理=========="+e.getMessage());

        Map<String,Object> map=new HashMap<>();
        map.put("code",e.getMessage());

        return map;
    }
}
